import urllib2
import logging
import datetime
from google.appengine.ext import db
from lib.toolbox import Render
from datetime import datetime, timedelta

class Sites(db.Model):
      url = db.StringProperty(required = True)
      xpath = db.StringProperty(required = True)
      rate = db.IntegerProperty(required = True)
      old_content = db.TextProperty(required = False)
      content = db.TextProperty(required = False)
      name = db.StringProperty(required = True)
      last_change = db.DateTimeProperty(required = False)
      last_check = db.DateTimeProperty(required = False)
      user = db.StringProperty(required = True)
      notification_type = db.StringProperty(required = True)

class Monitor(Render):
	
	def update(self):

		sites = db.GqlQuery("SELECT * FROM Sites")

		for site in sites:

			if ((datetime.now()-site.last_change) == site.rate):
				print "change"
			

		for e in u:
			usock = urllib2.urlopen(e.url)
			data = usock.read()
			usock.close()

			rdf_tree = xml.dom.minidom.parseString(data)
			context = xpath.XPathContext(rdf_tree)

			name    = context.findvalue(e.xpath, rdf_tree)

	def get(self):

		test = (datetime.now() - datetime(1984, 6, 29 ))
		print test.days






